
#include <iostream>
#include <string>
#include <memory>
#include <vector>

// 抽象类：员工接口
class Employee {
public:
    virtual ~Employee() = default;
    virtual std::string getName() const = 0;
    virtual bool isNull() const = 0;
};

// 具体类：真实员工
class RealEmployee : public Employee {
private:
    std::string name;

public:
    explicit RealEmployee(const std::string& name) : name(name) {}

    std::string getName() const override {
        return name;
    }

    bool isNull() const override {
        return false;
    }
};

// 空对象类：空员工
class NullEmployee : public Employee {
public:
    std::string getName() const override {
        return "No Employee Found";
    }

    bool isNull() const override {
        return true;
    }
};

// 工厂类：用于创建员工对象
class EmployeeFactory {
private:
    std::vector<std::string> employeeDatabase = {"Alice", "Bob", "Charlie"};

public:
    std::shared_ptr<Employee> getEmployee(const std::string& name) {
        for (const auto& emp : employeeDatabase) {
            if (emp == name) {
                return std::make_shared<RealEmployee>(name);
            }
        }
        return std::make_shared<NullEmployee>();
    }
};

// 客户端代码
int main() {
    EmployeeFactory factory;

    // 获取员工对象
    auto emp1 = factory.getEmployee("Alice");
    auto emp2 = factory.getEmployee("David");
    auto emp3 = factory.getEmployee("Charlie");

    // 客户端处理逻辑，无需显式检查空值
    std::cout << "Employee 1: " << emp1->getName() << "\n";
    std::cout << "Employee 2: " << emp2->getName() << "\n";
    std::cout << "Employee 3: " << emp3->getName() << "\n";

    return 0;
}